clear memory
clear all
clc

addpath("bbcsport\");
addpath("yaleA\");
addpath("MSRCV1");
addpath("ORL\");
addpath("Caltech101-7\");
addpath("scene15\");
addpath("Caltech101-all\");

Dataname = 'yaleA';
load(Dataname)
percentDel = 0.1;
Datanfold = [Dataname,'_percentDel_',num2str(percentDel),'.mat'];
load(Datanfold);

f = 1;
ind_folds = folds{f};  
truthF = Y+1;
clear Y
numClust = length(unique(truthF));
clear new_folds KnnGraph

numSmp = 0;

for iv = 1:length(X)
    X1 = X{iv}';
    X1 = NormalizeFea(X1,0);  
    numSmp=numSmp + size(X{iv},1);
    ind_0 = find(ind_folds(:,iv) == 0);
    ind_1 = find(ind_folds(:,iv) == 1);

   
    linshi_A = eye(size(X{iv},1));
    linshi_A(:,ind_0) = [];
    A{iv} = linshi_A*linshi_A';

   
    X1(:,ind_0) = [];
    options = [];
    options.NeighborMode = 'KNN';
    k1=3;
    options.k = k1;
    options.WeightMode = 'Binary';    
    Z1 = full(constructW(X1',options));
    Z1 = Z1- diag(diag(Z1));
    linshi_A = diag(ind_folds(:,iv));
    linshi_A(:,ind_0) = [];
    Z_ini{iv} = linshi_A*max(Z1,Z1')*linshi_A';

    clear Z1 linshi_A
end
clear X1 X ind_0 ind_1

max_iter = 120;
theta = 1e-2;
rho = 1.2;


lambda1 = 0.01;
lambda2 = 1e-4;
delta = 0.1;
alpha=1e-5;
beta=1e-5;


[Z,F,obj,obj2] = MyFunction(Z_ini,A,numClust,lambda1,lambda2,theta,rho,max_iter,delta,alpha,beta);

Fng = NormalizeFea(F,1);
preLabel=kmeans(real(Fng),numClust,'maxiter',1000,'replicates',20,'EmptyAction','singleton');
res= ClusteringMeasure(truthF, preLabel)






